<?php
class Ob_blog extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    
    public function getBlog($id){
        return $this->db->get_where('ob_blog', array('id' =>$id))->row_array();
    }
    
    public function view($id){
        
    }
    
    public function getBlogList($username){
        $sql = "select id, title, create_dt from ob_blog where user = '" .$username."' order by create_dt desc, create_tm desc";
        $result = $this->db->query($sql);
        return $result->result_array();
    }
    
    public function getRecentBlogList($username){
        $sql = "select id, title, create_dt from ob_blog where user = '" .$username."' order by create_dt desc, create_tm desc limit 10";
        $result = $this->db->query($sql);
        return $result->result_array();
    }
    
    public function getDefaultBlog($username){
        $sql = "select title, content, create_dt, create_tm from ob_blog  where  user = '".$username."' order by create_dt desc, create_tm desc limit 1"  ;
        $result = $this->db->query($sql);
        return $result->row_array();
    }
    
    public function insertBlog($username,$title,$content){
        if(empty($username) || empty($title) ||empty($content) ){
            return false;
        }else{
            return $this->db->insert('ob_blog',array('title' => $title, 'content' => $content, 'user' => $username, 'create_dt' => date('Y-m-d'), 'create_tm' => date('H:i:s')));
        }
        
    }
    
}
